#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1000010 * 2;

int n;
char a[N], b[N];

int get_min(char a[]){
    int i = 0, j = 1;
    while(i < n && j < n){
        int k = 0;
        while(k < n && a[i + k] == a[j + k]) k ++;

        if(k == n) break;

        if(a[i + k] > a[j + k]) i += k + 1;
        else j += k + 1;
        if(i == j) j ++;
    }

    int k = min(i, j);
    a[k + n] = 0;
    return k;
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    scanf("%s%s", a, b);
    n = strlen(a);
    memcpy(a + n, a, n);
    memcpy(b + n, b, n);

    int x = get_min(a), y = get_min(b);
    if(strcmp(a + x, b + y)){
        printf("No\n");
    }else{
        printf("Yes\n");
        printf("%s\n", a + x);
    }

    return 0;
}